<?php
// this is the index site for our einstein module
// it is automatically appended on the applications main ./index.php
// by the dPframework

// we check for permissions on this module
$canRead = !getDenyRead( $m );		// retrieve module-based readPermission bool flag
$canEdit = !getDenyEdit( $m );		// retrieve module-based writePermission bool flag

if (!$canRead) {			// lock out users that do not have at least readPermission on this module
	$AppUI->redirect( "m=public&a=access_denied" );
}

$AppUI->savePlace('m=home');

// retrieve any state parameters (temporary session variables that are not stored in db)

if (isset( $_GET['tab'] )) {
	$AppUI->setState( 'HomeDataIdxTab', $_GET['tab'] );		// saves the current tab box state
}
$tab = $AppUI->getState( 'HomeDataIdxTab' ) !== NULL ? $AppUI->getState( 'HomeDataIdxTab' ) : 0;	// use first tab if no info is available
$active = intval( !$AppUI->getState( 'HomeDataIdxTab' ) );						// retrieve active tab info for the tab box that
													// will be created down below
// we prepare the User Interface Design with the dPFramework

// setup the title block with Name, Icon and Help

$titleBlock = new CTitleBlock( 'Home page', 'home48x48.png', $m, "$m.$a" );
$titleBlock->addCell();
$titleBlock->show();

$screens4Role = array(
	'Accounting' => array("account_receivable", "references", "tasks"),
	'Marketing' => array("process_reference", "quotations"),
	'FFIA_Management' => array("tasks", "references"),
	'FFIA_Staff' => array("tasks", "references"),
	'Operation' => array("tasks"),
	'General_Management' => array("references"),
);

$screensName = array(
	"account_receivable" => "Account Receivable",
	"process_reference" => "Process References",
	"references" => "References",
	"quotations" => "Quotations",
	"tasks" => "Tasks",
	"customers" => "Customers"
);

$perm = & $AppUI->acl();
$roles = $perm->getUserRoles($AppUI->user_id);
$userScreens = array();
foreach($roles as $role) {
	$screens = $screens4Role[$role['value']];
	if ($screens && count($screens) > 0) {
		if (count($userScreens) === 0) {
			$userScreens = array_merge($userScreens, $screens);
		} else {
			$diff = array_diff($screens, $userScreens);
			$userScreens = array_merge($userScreens, $diff);
		}
	}
}
// build new tab box object
$tabBox = new CTabBox( "?m=home", $tab );
//$tabBox->loadExtras($m,"list");

foreach($userScreens as $screen) {
	$tabBox->add($screen, $screensName[$screen]);
}

//$perms =& $AppUI->acl();
//$isFfiaRole = $perms->checkModuleItem( "projects", 'edit');
//$task_not_quotation= $isFfiaRole? 0:1;
//$perm = & $AppUI->acl();
//if ($perm->userHasRole($AppUI->user_id, 'Accounting')
//|| $perm->userHasRole($AppUI->user_id, 'Marketing')
//|| $perm->userHasRole($AppUI->user_id, 'FFIA_Management')
//|| $perm->userHasRole($AppUI->user_id, 'FFIA_Staff')) {
//	$tabBox->add( 'references', 'References' );
//}

$tabBox->show();						// finally show the tab box
?>